package com.cos.lession56.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: COS
 * @time: 2022/3/10 16:34
 * @description:
 */
public class MyInterceptor implements HandlerInterceptor {
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/3/10 16:35
     * @description:
     * 相当于前置增强
     * 进入controller方法之前在执行
     *
     * boolean 返回值 false就是不放行   true放行
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入controller前的拦截");
        return true;
    }
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/3/10 16:36
     * @description:
     * 相当于后缀之前
     * 离开controller时候执行
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("离开controller后再次拦截");

    }
    /**
     *
     * @author: COS
     * @return:
     * @time: 2022/3/10 16:37
     * @description:
     * 前端控制器完成的view对象的数据渲染后会执行这个方法
     * 一般释放资源
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
